﻿<UserControl x:Class="GSF.PhasorProtocols.UI.UserControls.HistorianViewUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" Height="650">
    
    <UserControl.Resources>
        <ControlTemplate x:Key="DataGridTemplate" TargetType="DataGrid">
            <Border Background="{TemplateBinding Control.Background}" BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="{TemplateBinding Control.BorderThickness}" Padding="{TemplateBinding Control.Padding}" SnapsToDevicePixels="True">
                <ScrollViewer Focusable="False" Name="DG_ScrollViewer">
                    <ScrollViewer.Template>
                        <ControlTemplate TargetType="ScrollViewer">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <Button Command="ApplicationCommands.SelectAll" Focusable="False" Style="{DynamicResource {ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, TypeInTargetAssembly=DataGrid}}" Width="{Binding Path=CellsPanelHorizontalOffset, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType=DataGrid}}">
                                    <Button.Visibility>
                                        <Binding Path="HeadersVisibility" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType=DataGrid}">
                                            <Binding.ConverterParameter>
                                                <DataGridHeadersVisibility>All</DataGridHeadersVisibility>
                                            </Binding.ConverterParameter>
                                        </Binding>
                                    </Button.Visibility>
                                </Button>
                                <DataGridColumnHeadersPresenter Grid.Column="1" Name="PART_ColumnHeadersPresenter">
                                    <DataGridColumnHeadersPresenter.ContextMenu>
                                        <ContextMenu Initialized="ColumnContextMenu_Initialized"/>
                                    </DataGridColumnHeadersPresenter.ContextMenu>
                                    <DataGridColumnHeadersPresenter.Visibility>
                                        <Binding Path="HeadersVisibility" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType=DataGrid}">
                                            <Binding.ConverterParameter>
                                                <DataGridHeadersVisibility>Column</DataGridHeadersVisibility>
                                            </Binding.ConverterParameter>
                                        </Binding>
                                    </DataGridColumnHeadersPresenter.Visibility>
                                </DataGridColumnHeadersPresenter>
                                <ScrollContentPresenter CanContentScroll="{TemplateBinding ScrollViewer.CanContentScroll}" CanHorizontallyScroll="False" CanVerticallyScroll="False" Content="{TemplateBinding ContentControl.Content}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" Grid.ColumnSpan="2" Grid.Row="1" Name="PART_ScrollContentPresenter" />
                                <ScrollBar Grid.Column="2" Grid.Row="1" Maximum="{TemplateBinding ScrollViewer.ScrollableHeight}" Name="PART_VerticalScrollBar" Orientation="Vertical" Value="{Binding Path=VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ScrollViewer.ViewportHeight}" Visibility="{TemplateBinding ScrollViewer.ComputedVerticalScrollBarVisibility}" />
                                <Grid Grid.Column="1" Grid.Row="2">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="{Binding Path=NonFrozenColumnsViewportHorizontalOffset, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType=DataGrid}}" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>
                                    <ScrollBar Grid.Column="1" Maximum="{TemplateBinding ScrollViewer.ScrollableWidth}" Name="PART_HorizontalScrollBar" Orientation="Horizontal" Value="{Binding Path=HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ScrollViewer.ViewportWidth}" Visibility="{TemplateBinding ScrollViewer.ComputedHorizontalScrollBarVisibility}" />
                                </Grid>
                            </Grid>
                        </ControlTemplate>
                    </ScrollViewer.Template>
                    <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                </ScrollViewer>
            </Border>
        </ControlTemplate>
    </UserControl.Resources>
    <DockPanel>
        <Menu Height="23" DockPanel.Dock="Top">
            <Menu.Resources>
                <Style TargetType="{x:Type Image}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuItem}, AncestorLevel=1}, Path=IsEnabled}" Value="False">
                            <Setter Property="Opacity" Value="0.50" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Menu.Resources>
            <MenuItem Header="_File"  Padding="0">
                <MenuItem Header="Open a_rchive..." InputGestureText="Ctrl+R" Click="OpenArchiveControl_Click">
                    <MenuItem.Icon>
                        <Image Source="/GSF.TimeSeries.UI;component/Images/CabinetOpen.png" MaxWidth="20" MaxHeight="20" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="_Open..." Click="OpenControl_Click" InputGestureText="Ctrl+O">
                    <MenuItem.Icon>
                        <Image Source="/GSF.TimeSeries.UI;component/Images/Folder.png" MaxWidth="20" MaxHeight="20" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="_Save" InputGestureText="Ctrl+S" IsEnabled="False" Name="m_saveMenuItem" Click="SaveControl_Click">
                    <MenuItem.Icon>
                        <Image Source="/GSF.TimeSeries.UI;component/Images/Save.png" MaxWidth="20" MaxHeight="20" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Save _as..." InputGestureText="Ctrl+Shift+S" IsEnabled="False" Name="m_saveAsMenuItem" Click="SaveAsMenuItem_Click" />
                <Separator />
                <MenuItem Header="_Close" InputGestureText="Alt+F4" Click="CloseMenuItem_Click" />
            </MenuItem>
            <MenuItem Header="_Options" Padding="0">
                <MenuItem Header="Trend" Name="m_trendMenuItem" IsEnabled="False" Click="TrendControl_Click">
                    <MenuItem.Icon>
                        <Image Source="/GSF.TimeSeries.UI;component/Images/ChartLine.png" MaxWidth="20" MaxHeight="20" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Export..." Name="m_exportMenuItem" IsEnabled="False" Click="ExportControl_Click">
                    <MenuItem.Icon>
                        <Image Source="/GSF.TimeSeries.UI;component/Images/TableEdit.png" MaxWidth="20" MaxHeight="20" />
                    </MenuItem.Icon>
                </MenuItem>
            </MenuItem>
        </Menu>
        <ToolBarTray DockPanel.Dock="Top" Width="850" VerticalAlignment="Top">
            <ToolBar BorderThickness="1" BorderBrush="DarkGray">
                <ToolBar.Resources>
                    <Style TargetType="{x:Type Image}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}, AncestorLevel=1}, Path=IsEnabled}" Value="False">
                                <Setter Property="Opacity" Value="0.50" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ToolBar.Resources>
                <ToolBarTray DockPanel.Dock="Top">
                    <ToolBar BorderThickness="1" BorderBrush="DarkGray">
                        <ToolBar.Resources>
                            <Style TargetType="{x:Type Image}">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}, AncestorLevel=1}, Path=IsEnabled}" Value="False">
                                        <Setter Property="Opacity" Value="0.50" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </ToolBar.Resources>
                        <Button Width="23" Height="23" ToolTip="Open Archive... (Ctrl+R)" Click="OpenArchiveControl_Click">
                            <Image Source="/GSF.TimeSeries.UI;component/Images/CabinetOpen.png" />
                        </Button>
                        <Button Width="23" Height="23" Click="OpenControl_Click" ToolTip="Open (Ctrl+O)">
                            <Image Source="/GSF.TimeSeries.UI;component/Images/Folder.png" />
                        </Button>
                        <Button Width="23" Height="23" ToolTip="Save (Ctrl+S)" IsEnabled="False" Name="m_saveButton" Click="SaveControl_Click" ToolTipService.ShowOnDisabled="True">
                            <Image Source="/GSF.TimeSeries.UI;component/Images/Save.png" />
                        </Button>
                        <Separator />
                        <Button Width="23" Height="23" Click="TrendControl_Click" ToolTip="Trend" ToolTipService.ShowOnDisabled="True" Name="m_trendButton" IsEnabled="False">
                            <Image Source="/GSF.TimeSeries.UI;component/Images/ChartLine.png" />
                        </Button>
                        <Button Width="23" Height="23" ToolTip="Export" ToolTipService.ShowOnDisabled="True" Name="m_exportButton" IsEnabled="False" Click="ExportControl_Click">
                            <Image Source="/GSF.TimeSeries.UI;component/Images/TableEdit.png" />
                        </Button>
                        <Separator />
                        <ToolBarPanel Orientation="Horizontal">
                            <Label Content="Search:" />
                            <TextBox Width="100" TextChanged="SearchBox_TextChanged" Name="m_searchBox" />
                        </ToolBarPanel>
                        <ToolBar.Background>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="White" Offset="0" />
                                <GradientStop Color="GhostWhite" Offset="0.52" />
                            </LinearGradientBrush>
                        </ToolBar.Background>
                    </ToolBar>
                </ToolBarTray>
                
            </ToolBar>
        </ToolBarTray>
        <Grid DockPanel.Dock="Bottom" Height="430" VerticalAlignment="Top">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="350" />
                <ColumnDefinition Width="428*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <StackPanel HorizontalAlignment="Left" Margin="10,0,10,10" VerticalAlignment="Top" Grid.Row="1">
                <StackPanel Name="m_currentTimeStackPanel" Orientation="Horizontal" Visibility="Visible">
                    <Label Content="Last" Height="23" Margin="5" VerticalAlignment="Top" Padding="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" />
                    <TextBox Height="23" Width="33" Text="5" HorizontalContentAlignment="Right" Margin="5" VerticalAlignment="Top" Name="m_currentTimeTextBox" PreviewTextInput="NumericTextBox_PreviewTextInput">
                        <TextBox.CommandBindings>
                            <CommandBinding Command="ApplicationCommands.Paste" CanExecute="NumericTextBox_PasteCommandBinding_CanExecute" Executed="NumericTextBox_PasteCommandBinding_Executed" />
                        </TextBox.CommandBindings>
                    </TextBox>
                    <ComboBox Height="23" Width="120" SelectedIndex="1" Margin="5" VerticalAlignment="Top" Name="m_currentTimeComboBox">
                        <ComboBoxItem Content="seconds" />
                        <ComboBoxItem Content="minutes" />
                        <ComboBoxItem Content="hours" />
                        <ComboBoxItem Content="days" />
                    </ComboBox>
                </StackPanel>
                <StackPanel Orientation="Horizontal"></StackPanel>
                <StackPanel Orientation="Horizontal"></StackPanel>
                <Grid Height="70" Name="m_historicTimeGrid" Width="Auto">
                    <Grid.Resources>
                        <Style TargetType="{x:Type DatePicker}">
                            <EventSetter Event="Loaded" Handler="DatePicker_Loaded" />
                        </Style>
                    </Grid.Resources>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="125" />
                    </Grid.ColumnDefinitions>
                    <Label Content="UTC Start Time:" Height="25" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5" Padding="0" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" />
                    <DatePicker Height="25" Width="115" Grid.Column="1" Grid.Row="0" HorizontalAlignment="Left"  Name="m_startTimeDatePicker" Margin="5"  SelectedDateChanged="StartTimeDatePicker_SelectedDateChanged"/>
                    <Label Content="UTC End Time:" Height="25" Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Padding="0" />
                    <TextBox Height="25" Width="85" Text="12:00:00.000" Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5" Name="m_startTimeTextBox" TextChanged="StartTimeTextBox_TextChanged" />
                    <DatePicker Height="25" HorizontalAlignment="Left" Margin="5" VerticalAlignment="Top" Width="115" Grid.Column="1" Grid.Row="1" Name="m_endTimeDatePicker" SelectedDateChanged="EndTimeDatePicker_SelectedDateChanged"/>
                    <TextBox Height="25" HorizontalAlignment="Left" Margin="5" VerticalAlignment="Top" Width="85" Grid.Column="2" Grid.Row="1" Text="11:59:59.000" Name="m_endTimeTextBox" TextChanged="EndTimeTextBox_TextChanged" />
                </Grid>
                <CheckBox Content="Choose an interval relative to current time" Height="22" Margin="5,0" Name="m_currentTimeCheckBox" Checked="CurrentTimeCheckBox_Checked" Unchecked="CurrentTimeCheckBox_Unchecked"  Padding="0"/>
            </StackPanel>
            <DataGrid Name="m_dataGrid" AutoGenerateColumns="True" AutoGeneratingColumn="DataGrid_AutoGeneratingColumn" Template="{StaticResource DataGridTemplate}" AutoGeneratedColumns="DataGrid_AutoGeneratedColumns" SelectionUnit="Cell" SelectionMode="Single" Grid.ColumnSpan="2"  Height="500">
                <DataGrid.Resources>
                    <Style TargetType="{x:Type DataGridCell}">
                        <EventSetter Event="PreviewMouseLeftButtonDown" Handler="DataGridCell_PreviewMouseLeftButtonDown" />
                        <EventSetter Event="CheckBox.Checked" Handler="DataGridCell_CheckBoxChecked" />
                        <EventSetter Event="CheckBox.Unchecked" Handler="DataGridCell_CheckBoxUnchecked" />
                    </Style>
                </DataGrid.Resources>
            </DataGrid>
            <StackPanel Grid.Column="1" Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,10,10" Orientation="Horizontal">
                <Label Content="Chart resolution:" Height="32" VerticalAlignment="Center" />
                <TextBox Height="23" Width="50" Text="100" HorizontalContentAlignment="Right" Name="m_chartResolutionTextBox" KeyDown="ChartResolutionTextBox_KeyDown" PreviewTextInput="NumericTextBox_PreviewTextInput">
                    <TextBox.CommandBindings>
                        <CommandBinding Command="ApplicationCommands.Paste" CanExecute="NumericTextBox_PasteCommandBinding_CanExecute" Executed="NumericTextBox_PasteCommandBinding_Executed" />
                    </TextBox.CommandBindings>
                </TextBox>
                <Label Content="samples" Height="32" />
            </StackPanel>
        </Grid>
    </DockPanel>
</UserControl>
